<?php
$dbhost = 'localhost:3036';
$dbuser = 'va';
$dbpass = 'dummy';
$dbname = 'va_stratlab';

$con = mysql_connect($dbhost, $dbuser, $dbpass);

if (!$con) 
  die('Could not connect: ' . mysql_error());

mysql_select_db($dbname, $con);

$sql = "SELECT DISTINCT `datechar` FROM  `stockprice` ORDER BY `datechar`";
$result = mysql_query($sql);

$alldates=array();
while($row = mysql_fetch_array($result)) {
  $alldates[]=$row[0];
}

foreach ($alldates as $datechar) {
  $sql="UPDATE `stockprice` SET `date` ='".substr($datechar,0,4)."-".substr($datechar,4,2)."-".substr($datechar,6,2)."' WHERE `datechar` = '$datechar'";
  echo $sql."\n";
  $result = mysql_query($sql);
  if (!$result) die('Update Error'. mysql_error());
} 

mysql_close($con);
?>
